import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-07-21
 * Time: 22:27
 */
class Solution11 {
    public String[] sortPeople(String[] names, int[] heights) {
        int n = names.length;

        //1.创建一个下标数组
        Integer[] index = new Integer[n];

        for(int i = 0; i < n; i++) {
            index[i] = i;
        }

        //2.对下标数组排序
        Arrays.sort(index,(i, j) -> {
            return heights[j]-heights[i];
        });

        //3.提取结果
        String[] ret = new String[n];
        for(int i = 0; i < n; i++) {
            ret[i] = names[index[i]];
        }
        return ret;
    }
}


//解法二：哈希表
//class Solution {
//    public String[] sortPeople(String[] names, int[] heights) {
//        int n = names.length,index = 0;
//
//        Map<Integer,String> hash = new HashMap<>();
//
//        for(int i = 0; i < n; i++) {
//            hash.put(heights[i],names[i]);
//        }
//
//        Arrays.sort(heights);
//
//        String[] ret  = new String[n];
//
//        for(int i = n-1;i >= 0; i--) {
//            ret[index] = hash.get(heights[i]);
//            index++;
//        }
//        return ret;
//    }
//}
